{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 题目描述\n",
    "There are two sorted arrays nums1 and nums2 of size m and n respectively.\n",
    "\n",
    "Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).\n",
    "\n",
    "You may assume nums1 and nums2 cannot be both empty.\n",
    "\n",
    "Example 1:\n",
    "\n",
    "nums1 = [1, 3]\n",
    "nums2 = [2]\n",
    "\n",
    "The median is 2.0\n",
    "\n",
    "Example 2:\n",
    "\n",
    "nums1 = [1, 2]\n",
    "nums2 = [3, 4]\n",
    "\n",
    "The median is (2 + 3)/2 = 2.5\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 解题思路\n",
    "这里难点是时间复杂度的限制，不考虑时间复杂度的情况还是比较简单的...这里先写下后者的实现。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-20T14:45:50.288075Z",
     "start_time": "2019-01-20T14:45:50.283119Z"
    }
   },
   "source": [
    "### Python代码[ 98.63%]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-20T14:46:04.025102Z",
     "start_time": "2019-01-20T14:46:04.010695Z"
    }
   },
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def findMedianSortedArrays(self, nums1, nums2):\n",
    "        \"\"\"\n",
    "        :type nums1: List[int]\n",
    "        :type nums2: List[int]\n",
    "        :rtype: float\n",
    "        \"\"\"\n",
    "        nums = sorted(nums1+nums2)\n",
    "        N = len(nums)\n",
    "        n = N // 2\n",
    "        if N % 2 == 1:\n",
    "            return nums[n]\n",
    "        else:\n",
    "            return (nums[n]+nums[n-1])/2\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-20T14:46:20.332750Z",
     "start_time": "2019-01-20T14:46:20.321686Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "# 测试\n",
    "nums1 = [1, 2, 3, 5]\n",
    "nums2 = [3, 4, 6, 7, 8]\n",
    "solve = Solution()\n",
    "print(solve.findMedianSortedArrays(nums1, nums2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
